<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>query(rtree&lt;...&gt; const &amp;, Predicates const &amp;, OutIter)</title>
<link rel="stylesheet" href="../../../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../../../index.html" title="Chapter 1. Geometry">
<link rel="up" href="../group__rtree__functions.html" title="R-tree free functions (boost::geometry::index::)">
<link rel="prev" href="remove_rtree_________convertibleorrange_const___.html" title="remove(rtree&lt;...&gt; &amp;, ConvertibleOrRange const &amp;)">
<link rel="next" href="qbegin_rtree______const____predicates_const___.html" title="qbegin(rtree&lt;...&gt; const &amp;, Predicates const &amp;)">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="remove_rtree_________convertibleorrange_const___.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../group__rtree__functions.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="qbegin_rtree______const____predicates_const___.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h5 class="title">
<a name="geometry.reference.spatial_indexes.group__rtree__functions.query_rtree______const____predicates_const____outiter_"></a><a name="group__rtree__functions_1gadb43b211d5d743ebe2ef256328286e95"></a><a class="link" href="query_rtree______const____predicates_const____outiter_.html" title="query(rtree&lt;...&gt; const &amp;, Predicates const &amp;, OutIter)">query(rtree&lt;...&gt;
          const &amp;, Predicates const &amp;, OutIter)</a>
</h5></div></div></div>
<p>
            <a class="indexterm" name="idm45246415699632"></a>
Finds values meeting passed predicates e.g. nearest to some Point and/or
            intersecting some Box.
          </p>
<h6>
<a name="geometry.reference.spatial_indexes.group__rtree__functions.query_rtree______const____predicates_const____outiter_.h0"></a>
            <span class="phrase"><a name="geometry.reference.spatial_indexes.group__rtree__functions.query_rtree______const____predicates_const____outiter_.description"></a></span><a class="link" href="query_rtree______const____predicates_const____outiter_.html#geometry.reference.spatial_indexes.group__rtree__functions.query_rtree______const____predicates_const____outiter_.description">Description</a>
          </h6>
<p>
            This query function performs spatial and k-nearest neighbor searches.
            It allows to pass a set of predicates. Values will be returned only if
            all predicates are met.
          </p>
<p>
            <span class="bold"><strong>Spatial predicates</strong></span>
          </p>
<p>
            Spatial predicates may be generated by one of the functions listed below:
          </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
                <code class="literal"><a class="link" href="../group__predicates/contains_geometry_const___.html#group__predicates_1gac52a6557110425d4ece53fbd6f9ff866">boost::geometry::index::contains()</a></code>,
              </li>
<li class="listitem">
                <code class="literal"><a class="link" href="../group__predicates/covered_by_geometry_const___.html#group__predicates_1ga02dbb7cca47de0b921ef96af464d9590">boost::geometry::index::covered_by()</a></code>,
              </li>
<li class="listitem">
                <code class="literal"><a class="link" href="../group__predicates/covers_geometry_const___.html#group__predicates_1ga0e92e4a20dd19185584fe85847439108">boost::geometry::index::covers()</a></code>,
              </li>
<li class="listitem">
                <code class="literal"><a class="link" href="../group__predicates/disjoint_geometry_const___.html#group__predicates_1ga0aa114ab16f40c8caeb3338adba5d6da">boost::geometry::index::disjoint()</a></code>,
              </li>
<li class="listitem">
                <code class="literal"><a class="link" href="../group__predicates/intersects_geometry_const___.html#group__predicates_1ga78cb2ef221b951867c591ffb51b7d8c5">boost::geometry::index::intersects()</a></code>,
              </li>
<li class="listitem">
                <code class="literal"><a class="link" href="../group__predicates/overlaps_geometry_const___.html#group__predicates_1ga4a6d33e6f61ad5bff3bdee50a972d54b">boost::geometry::index::overlaps()</a></code>,
              </li>
<li class="listitem">
                <code class="literal"><a class="link" href="../group__predicates/within_geometry_const___.html#group__predicates_1gaabce901b82af2aab10ebbd0dda12f4d5">boost::geometry::index::within()</a></code>,
              </li>
</ul></div>
<p>
            It is possible to negate spatial predicates:
          </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
                <code class="literal"><code class="computeroutput"><span class="special">!</span> </code><a class="link" href="../group__predicates/contains_geometry_const___.html#group__predicates_1gac52a6557110425d4ece53fbd6f9ff866">boost::geometry::index::contains()</a></code>,
              </li>
<li class="listitem">
                <code class="literal"><code class="computeroutput"><span class="special">!</span> </code><a class="link" href="../group__predicates/covered_by_geometry_const___.html#group__predicates_1ga02dbb7cca47de0b921ef96af464d9590">boost::geometry::index::covered_by()</a></code>,
              </li>
<li class="listitem">
                <code class="literal"><code class="computeroutput"><span class="special">!</span> </code><a class="link" href="../group__predicates/covers_geometry_const___.html#group__predicates_1ga0e92e4a20dd19185584fe85847439108">boost::geometry::index::covers()</a></code>,
              </li>
<li class="listitem">
                <code class="literal"><code class="computeroutput"><span class="special">!</span> </code><a class="link" href="../group__predicates/disjoint_geometry_const___.html#group__predicates_1ga0aa114ab16f40c8caeb3338adba5d6da">boost::geometry::index::disjoint()</a></code>,
              </li>
<li class="listitem">
                <code class="literal"><code class="computeroutput"><span class="special">!</span> </code><a class="link" href="../group__predicates/intersects_geometry_const___.html#group__predicates_1ga78cb2ef221b951867c591ffb51b7d8c5">boost::geometry::index::intersects()</a></code>,
              </li>
<li class="listitem">
                <code class="literal"><code class="computeroutput"><span class="special">!</span> </code><a class="link" href="../group__predicates/overlaps_geometry_const___.html#group__predicates_1ga4a6d33e6f61ad5bff3bdee50a972d54b">boost::geometry::index::overlaps()</a></code>,
              </li>
<li class="listitem">
                <code class="literal"><code class="computeroutput"><span class="special">!</span> </code><a class="link" href="../group__predicates/within_geometry_const___.html#group__predicates_1gaabce901b82af2aab10ebbd0dda12f4d5">boost::geometry::index::within()</a></code>
              </li>
</ul></div>
<p>
            <span class="bold"><strong>Satisfies predicate</strong></span>
          </p>
<p>
            This is a special kind of predicate which allows to pass a user-defined
            function or function object which checks if Value should be returned
            by the query. It's generated by:
          </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
                <code class="literal"><a class="link" href="../group__predicates/satisfies_unarypredicate_const___.html#group__predicates_1ga3213772dd3e54ad03340c2ca66b4f58c">boost::geometry::index::satisfies()</a></code>.
              </li></ul></div>
<p>
            <span class="bold"><strong>Nearest predicate</strong></span>
          </p>
<p>
            If the nearest predicate is passed a k-nearest neighbor search will be
            performed. This query will result in returning k values to the output
            iterator. Only one nearest predicate may be passed to the query. It may
            be generated by:
          </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
                <code class="literal"><a class="link" href="../group__predicates/nearest_geometry_const____std__size_t_.html#group__predicates_1ga476c3b5d51e60d5c8e1e743340cb2b2b">boost::geometry::index::nearest()</a></code>.
              </li></ul></div>
<p>
            <span class="bold"><strong>Connecting predicates</strong></span>
          </p>
<p>
            Predicates may be passed together connected with <code class="literal"><code class="computeroutput"><span class="keyword">operator</span><span class="special">&amp;&amp;()</span></code></code>.
          </p>
<h6>
<a name="geometry.reference.spatial_indexes.group__rtree__functions.query_rtree______const____predicates_const____outiter_.h1"></a>
            <span class="phrase"><a name="geometry.reference.spatial_indexes.group__rtree__functions.query_rtree______const____predicates_const____outiter_.synopsis"></a></span><a class="link" href="query_rtree______const____predicates_const____outiter_.html#geometry.reference.spatial_indexes.group__rtree__functions.query_rtree______const____predicates_const____outiter_.synopsis">Synopsis</a>
          </h6>
<pre class="programlisting"><code class="computeroutput"><span class="keyword">template</span><span class="special">&lt;</span></code><code class="computeroutput"><span class="keyword">typename</span> <span class="identifier">Value</span></code><code class="computeroutput"><span class="special">,</span></code>
         <code class="computeroutput"><span class="keyword">typename</span> <span class="identifier">Parameters</span></code><code class="computeroutput"><span class="special">,</span></code>
         <code class="computeroutput"><span class="keyword">typename</span> <span class="identifier">IndexableGetter</span></code><code class="computeroutput"><span class="special">,</span></code>
         <code class="computeroutput"><span class="keyword">typename</span> <span class="identifier">EqualTo</span></code><code class="computeroutput"><span class="special">,</span></code>
         <code class="computeroutput"><span class="keyword">typename</span> <span class="identifier">Allocator</span></code><code class="computeroutput"><span class="special">,</span></code>
         <code class="computeroutput"><span class="keyword">typename</span> <span class="identifier">Predicates</span></code><code class="computeroutput"><span class="special">,</span></code>
         <code class="computeroutput"><span class="keyword">typename</span> <span class="identifier">OutIter</span></code><code class="computeroutput"><span class="special">&gt;</span></code>
<code class="computeroutput"><span class="identifier">rtree</span><span class="special">&lt;</span> <span class="identifier">Value</span><span class="special">,</span> <span class="identifier">Parameters</span><span class="special">,</span> <span class="identifier">IndexableGetter</span><span class="special">,</span> <span class="identifier">EqualTo</span><span class="special">,</span> <span class="identifier">Allocator</span> <span class="special">&gt;::</span><span class="identifier">size_type</span></code> <code class="computeroutput"><span class="identifier">query</span></code><code class="computeroutput"><span class="special">(</span></code><code class="computeroutput"><span class="identifier">rtree</span><span class="special">&lt;</span> <span class="identifier">Value</span><span class="special">,</span> <span class="identifier">Parameters</span><span class="special">,</span> <span class="identifier">IndexableGetter</span><span class="special">,</span> <span class="identifier">EqualTo</span><span class="special">,</span> <span class="identifier">Allocator</span> <span class="special">&gt;</span> <span class="keyword">const</span> <span class="special">&amp;</span></code> <code class="computeroutput"><span class="identifier">tree</span></code><code class="computeroutput"><span class="special">,</span></code>
                                                                                 <code class="computeroutput"><span class="identifier">Predicates</span> <span class="keyword">const</span> <span class="special">&amp;</span></code> <code class="computeroutput"><span class="identifier">predicates</span></code><code class="computeroutput"><span class="special">,</span></code>
                                                                                 <code class="computeroutput"><span class="identifier">OutIter</span></code> <code class="computeroutput"><span class="identifier">out_it</span></code><code class="computeroutput"><span class="special">)</span></code>
</pre>
<h6>
<a name="geometry.reference.spatial_indexes.group__rtree__functions.query_rtree______const____predicates_const____outiter_.h2"></a>
            <span class="phrase"><a name="geometry.reference.spatial_indexes.group__rtree__functions.query_rtree______const____predicates_const____outiter_.parameter_s_"></a></span><a class="link" href="query_rtree______const____predicates_const____outiter_.html#geometry.reference.spatial_indexes.group__rtree__functions.query_rtree______const____predicates_const____outiter_.parameter_s_">Parameter(s)</a>
          </h6>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                    <p>
                      Type
                    </p>
                  </th>
<th>
                    <p>
                      Name
                    </p>
                  </th>
<th>
                    <p>
                      Description
                    </p>
                  </th>
</tr></thead>
<tbody>
<tr>
<td>
                    <p>
                      <code class="computeroutput"><span class="identifier">rtree</span><span class="special">&lt;</span>
                      <span class="identifier">Value</span><span class="special">,</span>
                      <span class="identifier">Parameters</span><span class="special">,</span>
                      <span class="identifier">IndexableGetter</span><span class="special">,</span>
                      <span class="identifier">EqualTo</span><span class="special">,</span>
                      <span class="identifier">Allocator</span> <span class="special">&gt;</span>
                      <span class="keyword">const</span> <span class="special">&amp;</span></code>
                    </p>
                  </td>
<td>
                    <p>
                      <code class="computeroutput"><span class="identifier">tree</span></code>
                    </p>
                  </td>
<td>
                    <p>
                      The rtree.
                    </p>
                  </td>
</tr>
<tr>
<td>
                    <p>
                      <code class="computeroutput"><span class="identifier">Predicates</span> <span class="keyword">const</span> <span class="special">&amp;</span></code>
                    </p>
                  </td>
<td>
                    <p>
                      <code class="computeroutput"><span class="identifier">predicates</span></code>
                    </p>
                  </td>
<td>
                    <p>
                      Predicates.
                    </p>
                  </td>
</tr>
<tr>
<td>
                    <p>
                      <code class="computeroutput"><span class="identifier">OutIter</span></code>
                    </p>
                  </td>
<td>
                    <p>
                      <code class="computeroutput"><span class="identifier">out_it</span></code>
                    </p>
                  </td>
<td>
                    <p>
                      The output iterator, e.g. generated by std::back_inserter().
                    </p>
                  </td>
</tr>
</tbody>
</table></div>
<h6>
<a name="geometry.reference.spatial_indexes.group__rtree__functions.query_rtree______const____predicates_const____outiter_.h3"></a>
            <span class="phrase"><a name="geometry.reference.spatial_indexes.group__rtree__functions.query_rtree______const____predicates_const____outiter_.returns"></a></span><a class="link" href="query_rtree______const____predicates_const____outiter_.html#geometry.reference.spatial_indexes.group__rtree__functions.query_rtree______const____predicates_const____outiter_.returns">Returns</a>
          </h6>
<p>
            The number of values found.
          </p>
<h6>
<a name="geometry.reference.spatial_indexes.group__rtree__functions.query_rtree______const____predicates_const____outiter_.h4"></a>
            <span class="phrase"><a name="geometry.reference.spatial_indexes.group__rtree__functions.query_rtree______const____predicates_const____outiter_.example"></a></span><a class="link" href="query_rtree______const____predicates_const____outiter_.html#geometry.reference.spatial_indexes.group__rtree__functions.query_rtree______const____predicates_const____outiter_.example">Example</a>
          </h6>
<p>
</p>
<pre class="programlisting"><span class="comment">// return elements intersecting box</span>
<span class="identifier">bgi</span><span class="special">::</span><span class="identifier">query</span><span class="special">(</span><span class="identifier">tree</span><span class="special">,</span> <span class="identifier">bgi</span><span class="special">::</span><span class="identifier">intersects</span><span class="special">(</span><span class="identifier">box</span><span class="special">),</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">back_inserter</span><span class="special">(</span><span class="identifier">result</span><span class="special">));</span>
<span class="comment">// return elements intersecting poly but not within box</span>
<span class="identifier">bgi</span><span class="special">::</span><span class="identifier">query</span><span class="special">(</span><span class="identifier">tree</span><span class="special">,</span> <span class="identifier">bgi</span><span class="special">::</span><span class="identifier">intersects</span><span class="special">(</span><span class="identifier">poly</span><span class="special">)</span> <span class="special">&amp;&amp;</span> <span class="special">!</span><span class="identifier">bgi</span><span class="special">::</span><span class="identifier">within</span><span class="special">(</span><span class="identifier">box</span><span class="special">),</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">back_inserter</span><span class="special">(</span><span class="identifier">result</span><span class="special">));</span>
<span class="comment">// return elements overlapping box and meeting my_fun value predicate</span>
<span class="identifier">bgi</span><span class="special">::</span><span class="identifier">query</span><span class="special">(</span><span class="identifier">tree</span><span class="special">,</span> <span class="identifier">bgi</span><span class="special">::</span><span class="identifier">overlaps</span><span class="special">(</span><span class="identifier">box</span><span class="special">)</span> <span class="special">&amp;&amp;</span> <span class="identifier">bgi</span><span class="special">::</span><span class="identifier">satisfies</span><span class="special">(</span><span class="identifier">my_fun</span><span class="special">),</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">back_inserter</span><span class="special">(</span><span class="identifier">result</span><span class="special">));</span>
<span class="comment">// return 5 elements nearest to pt and elements are intersecting box</span>
<span class="identifier">bgi</span><span class="special">::</span><span class="identifier">query</span><span class="special">(</span><span class="identifier">tree</span><span class="special">,</span> <span class="identifier">bgi</span><span class="special">::</span><span class="identifier">nearest</span><span class="special">(</span><span class="identifier">pt</span><span class="special">,</span> <span class="number">5</span><span class="special">)</span> <span class="special">&amp;&amp;</span> <span class="identifier">bgi</span><span class="special">::</span><span class="identifier">intersects</span><span class="special">(</span><span class="identifier">box</span><span class="special">),</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">back_inserter</span><span class="special">(</span><span class="identifier">result</span><span class="special">));</span>

<span class="comment">// For each found value do_something (it is a type of function object)</span>
<span class="identifier">tree</span><span class="special">.</span><span class="identifier">query</span><span class="special">(</span><span class="identifier">bgi</span><span class="special">::</span><span class="identifier">intersects</span><span class="special">(</span><span class="identifier">box</span><span class="special">),</span>
           <span class="identifier">boost</span><span class="special">::</span><span class="identifier">make_function_output_iterator</span><span class="special">(</span><span class="identifier">do_something</span><span class="special">()));</span>
</pre>
<p>
          </p>
<h6>
<a name="geometry.reference.spatial_indexes.group__rtree__functions.query_rtree______const____predicates_const____outiter_.h5"></a>
            <span class="phrase"><a name="geometry.reference.spatial_indexes.group__rtree__functions.query_rtree______const____predicates_const____outiter_.throws"></a></span><a class="link" href="query_rtree______const____predicates_const____outiter_.html#geometry.reference.spatial_indexes.group__rtree__functions.query_rtree______const____predicates_const____outiter_.throws">Throws</a>
          </h6>
<p>
            If Value copy constructor or copy assignment throws.
          </p>
<div class="warning"><table border="0" summary="Warning">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../../../../../doc/src/images/warning.png"></td>
<th align="left">Warning</th>
</tr>
<tr><td align="left" valign="top"><p>
              Only one <code class="literal"><a class="link" href="../group__predicates/nearest_geometry_const____std__size_t_.html#group__predicates_1ga476c3b5d51e60d5c8e1e743340cb2b2b">nearest()</a></code>
              predicate may be passed to the query. Passing more of them results
              in compile-time error.
            </p></td></tr>
</table></div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2009-2021 Barend Gehrels,
      Bruno Lalande, Mateusz Loskot, Adam Wulkiewicz, Oracle and/or its affiliates<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="remove_rtree_________convertibleorrange_const___.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../group__rtree__functions.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="qbegin_rtree______const____predicates_const___.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
